<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /*
             */
            var subsets = function (nums) {
                let path = []
                let res = [[]]
                function backTracking(path, start) {
                    //如果想要res.push()放在外面，那么start必须>nums.length，因为到了最后一个path.push(2)时，backTack([1,2,],3)i+1为3
                    //导致[1,2,3]推入不进去

                    /* 
                    但是这种写法不好，不如path.push()之后，直接res.push()，本来就是为了存放每次的path路径
                    */
                    if (start > nums.length) {
                        return
                    }
                    res.push([...path])
                    for (let i = start; i < nums.length; i++) {
                        path.push(nums[i])
                        backTracking(path, i + 1)
                        path.pop()
                    }
                }
                backTracking(path, 0)
                return res
            }
            console.log(subsets([1, 2, 3]))
        </script>
    </body>
</html>
